package net.wenku8.reader.api

import tools.jackson.databind.DeserializationFeature
import tools.jackson.databind.JsonNode
import tools.jackson.databind.MapperFeature
import tools.jackson.databind.ObjectMapper
import tools.jackson.dataformat.xml.XmlFactory
import tools.jackson.dataformat.xml.XmlMapper


fun xmlToJson(xml : String):String {
    val builder = XmlMapper.builder(XmlFactory())
    builder.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    builder.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
    val jsonNode: JsonNode? = builder.build().readTree(xml)
    val objectMapper = ObjectMapper()
    return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode)
}